package com.df.bpm.utils.businessViewerV2.business;

import com.df.bpm.utils.businessViewerV2.informatization.M_outputDTO;
import com.df.common.exception.BusinessException;

import javax.swing.*;
import java.util.List;

public class C_business {

    static Db_business database=new Db_business();

    public static void showBusinessDtoByOutput(Integer requirementId,M_outputDTO outputDTO){
        V_businessByOutput vBusinessByOutput=new V_businessByOutput(requirementId,outputDTO);
        vBusinessByOutput.repaint();
        vBusinessByOutput.setVisible(true);
    }

    public static void deleteBusiness(Integer businessInformationIndex) {
        int i= JOptionPane.showConfirmDialog(
                null,
                "放弃删除此业务","注意！默认不删除",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if(i==1){
            database.deleteBusiness(businessInformationIndex);
            JOptionPane.showMessageDialog(
                    null,
                    "删除成功", "注意",
                    JOptionPane.INFORMATION_MESSAGE);
        }else{
            JOptionPane.showMessageDialog(
                    null,
                    "取消删除", "注意",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    }

    public static void updateBusiness(M_business mBusiness, Integer requirementId) {
        mBusiness.setInformatizationRequirementIndex(requirementId);
        database.updateBusiness(mBusiness);
    }

    public static Integer addBusiness(M_business mBusiness, Integer requirementId, Integer entityId4Output) {
        mBusiness.setInformatizationRequirementIndex(requirementId);
        M_businessDto4CreateWithOutput temp= new M_businessDto4CreateWithOutput();
        temp.setInformatizationRequirementIndex(requirementId);
        temp.setBusinessDesc(mBusiness.getBusinessDesc());
        temp.setEntityID(mBusiness.getEntityID());
        temp.setBusinessEntityIndex4Output(entityId4Output);
        Integer id=database.newBusiness(temp);
        if(id!=null){
            return id;
        }else{
            throw new BusinessException("新增失败");
        }
    }

    public static List<M_businessDto> getBusinessDto(Integer entityId4Output) {
        return database.getBusinessDto(entityId4Output);
    }

    public static List<Integer> getGroupIds(Integer superior) {
        return database.getGroupIds(superior);
    }

    public static List<M_businessLocationsDTO4Subset> getLocationDto4Subsets(Integer superior, Integer groupId) {
        if(superior==null || groupId==null){
            return null;
        }
        return database.getLocationDto4Subsets(superior,groupId);
    }

    public static List<M_businessInputDto> getInputDtos(Integer business) {
        if(business==null){
            return null;
        }
        return database.getInputDtos(business);
    }

    public static List<M_businessOutputDto> getOutputDtos(Integer business) {
        if(business==null){
            return null;
        }
        return database.getOutputDtos(business);
    }

    public static List<M_businessLocationsDTO4Subset> getSuperiorDtos(Integer business) {
        if(business==null){
            return null;
        }
        return database.getSuperiorDtos(business);
    }

    public static void freshInputOutput(Integer business) {
        database.freshInputOutput(business);
    }

    public static void updateOutput(M_businessOutput temp) {
        database.updateOutput(temp);
    }

    public static void updateInput(M_businessInputDto temp) {
        database.updateInput(temp);
    }

    public static void deleteOutput(Integer businessOutputsIndex) {
        database.deleteOutput(businessOutputsIndex);
    }

    public static void deleteInput(Integer businessInputsIndex) {
        database.deleteInput(businessInputsIndex);
    }

    public static void deleteBusinessLocation(Integer businessLocationsIndex) {
        database.deleteBusinessLocations(businessLocationsIndex);
    }

    public static void updateBusinessLocation(M_businessLocationsDTO4Subset nLocation) {
        database.updateLocation(nLocation);
    }

    public static M_businessDto4Search selectOne(Integer requirementId) {
        V_businessDto4Search vBusinessDto4Search=new V_businessDto4Search(requirementId);
        vBusinessDto4Search.repaint();
        vBusinessDto4Search.setVisible(true);

        return vBusinessDto4Search.selectResult;
    }

    public static List<M_businessDto4Search> getBusinessDto4Search(M_businessDto4Search temp) {
        return database.getBusinessDto4Search(temp);
    }
}
